import {
  reqCategory1List,
  reqCategory2List,
  reqCategory3List
} from "@/api/product/category";

const state = {
  category1Id: "",
  category2Id: "",
  category3Id: "",
  category1List: [],
  category2List: [],
  category3List: []
};

const actions = {
  async getCategory1List({ commit }) {
    const data = await reqCategory1List();
    commit("GET_CATEGORY1_LIST", data);
  },
  async getCategory2List({ commit }, category1Id) {
    const data = await reqCategory2List(category1Id);
    commit("GET_CATEGORY2_LIST", { data, category1Id });
  },
  async getCategory3List({ commit }, category2Id) {
    const data = await reqCategory3List(category2Id);
    commit("GET_CATEGORY3_LIST", { data, category2Id });
  }
};

const mutations = {
  GET_CATEGORY1_LIST(state, data) {
    state.category1List = data;
  },
  GET_CATEGORY2_LIST(state, { data, category1Id }) {
    state.category2List = data;
    state.category1Id = category1Id;
    state.category2Id=""
    state.category3List=[]
  },
  GET_CATEGORY3_LIST(state, { data, category2Id }) {
    state.category3List = data;
    state.category2Id = category2Id;
    state.category3Id=""
  },
  SET_CATEGORY3ID(state, category3Id) {
    state.category3Id = category3Id;
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
